package com.cxf.windex.rest;

import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.MoneyLogBiz;
import com.cxf.windex.entity.BMeterials;
import com.cxf.windex.entity.MoneyLog;
import com.cxf.windex.enums.OperateEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @program: business_needs
 * @description: 资金记录Controller
 * @author: chenxf
 * @create: 2018-11-01 16:13
 **/
@Api(tags = {"通用 - 资金记录接口"})
@RestController
@RequestMapping("userb/moneyLog")
public class MoneyLogController extends BaseRestController<MoneyLogBiz,MoneyLog> {



  @ApiOperation(value = "查询资金记录", notes = "查询资金记录列表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "limit", value = "记录数 默认10", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "offset", value = "页码 默认 1", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "orderStr", value = "排序 默认desc", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "status", value = "状态", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "wxopenid", value = "微信 openid", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "operateType", value = "操作类型", required = false, paramType = "query", dataType = "String")
  })
  @GetMapping("/list")
  public TableResultResponse<MoneyLog> list(
      @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset,
      @RequestParam(defaultValue = "desc") String orderStr,String status,String wxopenid,String operateType) {
    List<MoneyLog> items = baseBiz.list(limit, offset, orderStr,status,wxopenid,operateType);
    PageInfo<MoneyLog> pageInfo = new PageInfo<>(items);
    return new TableResultResponse<MoneyLog>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
        offset, limit,
        items);
  }


  @ApiOperation(value = "提现成功", notes = "提现成功")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "notes", value = "提现失败原因", required = true, paramType = "query", dataType = "String"),
          @ApiImplicitParam(name = "zcCount", value = "提现金额", required = true, paramType = "query", dataType = "String"),
          @ApiImplicitParam(name = "id", value = "提现id", required = true, paramType = "query", dataType = "String")
  })
  @PostMapping("/cashSuc")
  public ObjectRestResponse txsuc(String notes,String zcCount, String id) {
    baseBiz.cashSuc(notes,zcCount,  id);
    return new ObjectRestResponse().rel(true).msg("提现成功");
  }

  @ApiOperation(value = "提现失败", notes = "提现失败")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "notes", value = "提现失败原因", required = true, paramType = "query", dataType = "String"),
          @ApiImplicitParam(name = "id", value = "提现id", required = true, paramType = "query", dataType = "String")
  })
  @PostMapping("/cashFail")
  public ObjectRestResponse txfail(String notes, String id) {
    baseBiz.cashFail(notes, id);
    return new ObjectRestResponse().rel(true).msg("提现失败");
  }
}
